#include "stdafx.h"
#include "MultiStimulus.h"

namespace SpikingNeuronLib
{
	MultiStimulus::MultiStimulus(System::Collections::Generic::IEnumerable<Stimulus^>^ stimuli, array<int>^ sequence)
	{
		_isEmpty = true;
		_sequence = sequence;

		_sourceStimuli = gcnew List<Stimulus^>(stimuli);

		_stimulusFiringData = gcnew array<array<array<int>^>^>(_sourceStimuli->Count);
		for (int i = 0; i < _sourceStimuli->Count; i++)
		{
			Stimulus^ stimulus = _sourceStimuli[i];
			_isEmpty &= stimulus->IsEmpty;
			_stimulusFiringData[i] = stimulus->GetNeuronFiringData(i);
		}
	}

	array<array<int>^>^ MultiStimulus::GetNeuronFiringData(int second)
	{
		int stimulusIndex = GetStimulusIndex(second);

		return _stimulusFiringData[stimulusIndex];
	}

	bool MultiStimulus::FiresAtTime(int second, int millisecond)
	{
		int stimulusIndex = GetStimulusIndex(second);

		return _stimulusFiringData[stimulusIndex][millisecond] != nullptr;
	}

	// Returns the list of neurons that fire in the specified one msec timeslot
	array<int>^ MultiStimulus::GetFiringNeurons(int second, int millisecond)
	{
		int stimulusIndex = GetStimulusIndex(second);

		return _stimulusFiringData[stimulusIndex][millisecond];
	}
}
